package com.ruoyi.system.controller;

import java.time.LocalDateTime;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.system.domain.TMessageRecord;
import com.ruoyi.system.service.ITMessageRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;

import java.util.Date;

/**
 * 消息记录Controller
 *
 * @author ruoyi
 * @date 2024-01-16
 */
@Api(value = "/system/record", tags = {"消息记录"})
@RestController
@RequestMapping("/system/record")
public class TMessageRecordController extends BaseController {
    @Autowired
    private ITMessageRecordService tMessageRecordService;

    /**
     * 查询消息记录列表
     */
    @ApiOperation(value = "查询消息记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = TMessageRecord.class, paramType = "body", dataType = "TMessageRecord", name = "tMessageRecord", value = "the tMessageRecord to list")
    })
    @GetMapping("/list")
    public TableDataInfo list(TMessageRecord tMessageRecord) {
        startPage();
        List<TMessageRecord> list = tMessageRecordService.selectTMessageRecordList(tMessageRecord);
        return getDataTable(list);
    }

    /**
     * 导出消息记录列表
     */
    @ApiOperation(value = "导出消息记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = TMessageRecord.class, paramType = "body", dataType = "TMessageRecord", name = "tMessageRecord", value = "the tMessageRecord")
    })
    @Log(title = "消息记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMessageRecord tMessageRecord) {
        List<TMessageRecord> list = tMessageRecordService.selectTMessageRecordList(tMessageRecord);
        ExcelUtil<TMessageRecord> util = new ExcelUtil<TMessageRecord>(TMessageRecord.class);
        util.exportExcel(response, list, "消息记录数据");
    }

    /**
     * 获取消息记录详细信息
     */
    @ApiOperation(value = "获取消息记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tMessageRecordService.selectTMessageRecordById(id));
    }

    /**
     * 新增消息记录
     */
    @ApiOperation(value = "新增消息记录")
    @Log(title = "消息记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMessageRecord tMessageRecord) {
        tMessageRecord.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        tMessageRecord.setCreateTime(LocalDateTime.now());
        return toAjax(tMessageRecordService.save(tMessageRecord));
    }

    /**
     * 修改消息记录
     */
    @ApiOperation(value = "修改消息记录 ")
    @Log(title = "消息记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMessageRecord tMessageRecord) {
        tMessageRecord.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        tMessageRecord.setUpdateTime(LocalDateTime.now());
        return toAjax(tMessageRecordService.updateById(tMessageRecord));
    }

    /**
     * 删除消息记录
     */
    @ApiOperation(value = "删除消息记录")
    @Log(title = "消息记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tMessageRecordService.deleteTMessageRecordByIds(ids));
    }
}
